﻿

using Microsoft.Office.Interop.Word;
using System.Threading.Tasks;

namespace Office
{
    public class PdfHelper : PdfInterface
    {
        public bool WordToPdf(string wordPath, string pdfPath)
        {
            try
            {
                // 创建Word应用程序对象
                Application wordApp = new Application();

                // 打开Word文档
                Document wordDoc = wordApp.Documents.Open(wordPath);

                // 将Word文档另存为PDF文件
                wordDoc.ExportAsFixedFormat(pdfPath, WdExportFormat.wdExportFormatPDF);

                // 关闭Word文档和应用程序对象
                wordDoc.Close();
                wordApp.Quit();

                // 返回
                return true;
            }
            catch
            {
                return false;
            }

        }
    }

    interface PdfInterface
    {
        bool WordToPdf(string wordPath, string pdfPath);
    }
}
